import 'package:amoy_ticket/controller/event/event_declration.dart';
import 'package:amoy_ticket/controller/event/movie_tabbar_two_event.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

class MovieTabBarTwoScreen extends StatefulWidget {
  final List isSelectList;
  MovieTabBarTwoScreen(this.isSelectList);

  @override
  State<MovieTabBarTwoScreen> createState() => _MovieTabBarTwoScreenState();
}

class _MovieTabBarTwoScreenState extends State<MovieTabBarTwoScreen> {
  // 放映影厅
  List _cinemaScreeningList = [
    'IMAX厅',
    'CGS中国巨幕厅',
    '杜比影院',
    '120帧',
    'MX4D厅',
    '4DX厅',
    'SCREENX',
    'DTS临境音',
    '融合厅',
    '杜比全景声厅',
    'realD厅',
    '巨幕厅',
    '4D厅',
    'VIP厅',
    '艺术影厅',
    '激光厅',
    '4K厅',
    '双机3D',
  ];
  // 影院服务
  List _cinemaServicesList = [
    '退票',
    '改签',
    '影城卡',
    '3D眼镜收费',
    '观影小食',
    '可停车',
  ];
  // 影院品牌
  List _cinemaBrandList = [
    '幸福蓝海国际影城',
    '万达影城',
    '卢米埃影城',
    '星轶影城',
    '金逸影城',
    '中影国际影城',
    '大地影院',
    '保利影城',
    '博纳影城',
    'CGV影城',
    '横店影城',
    'SFC影城',
    '苏宁影城',
    'UME影城',
    'DFC影城',
    '耳东影城',
    '光美金逸影城',
    '海上国际影城',
    '万象影城',
    '沃美影城',
    '星河国际影城',
    '星轶',
    '耀莱影城',
    '中宁影城',
    '其他',
  ];
  // 会员特权
  List _vipPrivilegeList = ['定制票纸纪念语', '定制专属取票语文'];
  List _isSelectList = [];

  @override
  void initState() {
    _isSelectList = [];
    _isSelectList = widget.isSelectList;

    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        Column(
          children: [
            Container(
              padding: EdgeInsets.symmetric(horizontal: 10.w),
              width: MediaQuery.of(context).size.width,
              height: 400.h,
              color: Colors.white,
              child: SingleChildScrollView(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    _screenButtonList('放映影厅', _cinemaScreeningList),
                    _screenButtonList('影院服务', _cinemaServicesList),
                    _screenButtonList('影院品牌', _cinemaBrandList),
                    _screenButtonList('会员特权', _vipPrivilegeList),
                  ],
                ),
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(horizontal: 10.w),
              height: 43.h,
              width: MediaQuery.of(context).size.width,
              color: Colors.white,
              child: Center(
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    SizedBox(
                      width: 165.w,
                      child: OutlinedButton(
                        style: OutlinedButton.styleFrom(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(15.r),
                          ),
                          side: BorderSide(width: 1, color: Colors.grey),
                        ),
                        onPressed: () {
                          eventBus
                              .fire(MovieTabTwoScreenEvent(_isSelectList = []));
                          SmartDialog.dismiss();
                        },
                        child: Text(
                          '清空',
                          style: TextStyle(
                            fontSize: 13.sp,
                            color: Colors.black,
                          ),
                        ),
                      ),
                    ),
                    SizedBox(
                      width: 165.w,
                      child: OutlinedButton(
                        style: OutlinedButton.styleFrom(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.circular(15.r),
                          ),
                          backgroundColor: Color(0xFFfa549c),
                        ),
                        onPressed: () {
                          eventBus.fire(MovieTabTwoScreenEvent(_isSelectList));
                          SmartDialog.dismiss();
                        },
                        child: Text(
                          '确定',
                          style: TextStyle(
                            color: Colors.white,
                            fontSize: 13.sp,
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            )
          ],
        ),
        GestureDetector(
          onTap: () {
            SmartDialog.dismiss();
          },
          child: Container(
            height: 120.w,
            color: Colors.black.withOpacity(0.6),
          ),
        )
      ],
    );
  }

  Widget _title(String name) {
    return Padding(
      padding: EdgeInsets.symmetric(vertical: 5.h),
      child: Text(
        name,
        style: TextStyle(color: Color(0xFF696b70)),
      ),
    );
  }

  Widget _screenButtonList(String name, List list) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        _title(name),
        Padding(
          padding: EdgeInsets.symmetric(vertical: 5.h),
          child: Wrap(
            spacing: 10.w,
            runSpacing: 8.h,
            alignment: WrapAlignment.spaceBetween,
            runAlignment: WrapAlignment.start,
            children: list.map((e) {
              bool _isSelect = false;
              _isSelectList.forEach((element) {
                if (element == e) {
                  _isSelect = true;
                }
              });
              return GestureDetector(
                onTap: () {
                  setState(() {
                    if (!_isSelectList.contains(e)) {
                      _isSelectList.add(e);
                    } else {
                      _isSelectList.remove(e);
                    }
                  });
                },
                child: Container(
                  padding: EdgeInsets.symmetric(vertical: 5.h),
                  width: 105.w,
                  decoration: BoxDecoration(
                      color: _isSelect ? Color(0xFFfef4f3) : Color(0xFFf5f6f8),
                      borderRadius: BorderRadius.circular(3.r)),
                  child: Center(
                    child: Text(
                      e,
                      style: TextStyle(
                        fontSize: 12.sp,
                        color: _isSelect ? Color(0xFFcd322f) : Colors.black,
                      ),
                    ),
                  ),
                ),
              );
            }).toList(),
          ),
        ),
        Divider(),
      ],
    );
  }
}
